package com.jstyle.jclifexd.view;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;

import com.jstyle.jclifexd.R;
import com.jstyle.jclifexd.utils.ScreenUtils;

/**
 * Բ��ͷ��
 * @author Administrator
 *
 */
public class MapDistanceView extends Drawable {

	private Bitmap mBitmap;
	private Paint mPaint;
	private int mWidth;
	private Paint paint;
	private int outWidth;
	int distance=0;
	int textSize;
	public MapDistanceView(Context context,int distance) {
		this.distance=distance;
		mBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.track_history);
//		BitmapShader bitmapShader = new BitmapShader(bitmap, TileMode.MIRROR,
//				TileMode.MIRROR);
		mWidth = Math.min(mBitmap.getWidth(), mBitmap.getHeight());
		mPaint = new Paint();
		textSize=ScreenUtils.dip2px(context, 9);
		mPaint.setAntiAlias(true);
		//mPaint.setShader(bitmapShader);
		
	
	}

	@Override
	public void draw(Canvas canvas) {

		mPaint.setColor(Color.WHITE);
		mPaint.setTextSize(textSize);
		Rect rect = new Rect();
		String stepValue=String.valueOf(distance);
		mPaint.getTextBounds(stepValue, 0, stepValue.length(), rect);
		int height = rect.height();
		int width=rect.width();
		canvas.drawBitmap(mBitmap,mWidth/2-mBitmap.getWidth()/2 , mWidth/2-mBitmap.getHeight()/2 , mPaint);
		canvas.drawText(stepValue,
				mWidth/2-width*5/8,mWidth/2+height/2 ,mPaint);//无法居中？
	}

	@Override
	public int getIntrinsicWidth() {
		return mWidth;
	}

	@Override
	public int getIntrinsicHeight() {
		return mWidth;
	}

	@Override
	public void setAlpha(int alpha) {
		mPaint.setAlpha(alpha);
	}

	@Override
	public void setColorFilter(ColorFilter cf) {
		mPaint.setColorFilter(cf);
	}

	@Override
	public int getOpacity() {
		return PixelFormat.TRANSLUCENT;
	}
}
